﻿// 功能：渐变色填充的圆角按钮
// 描述：
// 作者：温伟鹏
// 日期：2010/6/6 21:39:47

using System;
using System.Runtime.InteropServices;
using MeizuSDK.Drawing;
using System.Drawing;

namespace MeizuSDK.Presentation
{
    /// <summary>
    /// 渐变色填充的圆角按钮
    /// </summary>
    public class GradientButton : Button
    {
        #region DllImport
        [DllImport("MZFCWrapper.dll")]
        private static extern IntPtr UiButton_GradientWrapperCtor(PaintWinFunc onPaintWin, MouseEventFunc onLButtonDblClk,
            MouseEventFunc onLButtonDown, MouseEventFunc onLButtonUp, MouseEventFunc onMouseMove);

        [DllImport("MZFCWrapper.dll")]
        private static extern NativeGradientButtonColor UiButton_GradientWrapperGetGradientColor(IntPtr pObj);

        [DllImport("MZFCWrapper.dll")]
        private static extern void UiButton_GradientWrapperDefaultPaintWin(IntPtr pObj, IntPtr hdcDst, ref RECT prcWin, ref RECT prcUpdate);

        [DllImport("MZFCWrapper.dll")]
        private static extern void UiButton_GradientWrapperSetGradientColor(IntPtr pObj,ref NativeGradientButtonColor gradColor);
        #endregion

        #region 公共属性
        /// <summary>
        /// 获取此按钮设置的渐变色
        /// </summary>
        public GradientButtonColor GradientColor
        {
            get{
                NativeGradientButtonColor ngbc = UiButton_GradientWrapperGetGradientColor(Handle);
                return GradientButtonColor.FromGBC(ngbc);
            }
            set{
                if(value!=null)
                {
                    NativeGradientButtonColor ngbc = value.ToGBC();

                    UiButton_GradientWrapperSetGradientColor(Handle, ref ngbc);
                }
            }
        }
        #endregion

        #region 构造函数
        /// <summary>
        /// 构造渐变色填充按钮
        /// </summary>
        public GradientButton()
        {
            Handle = UiButton_GradientWrapperCtor(PaintWinDelegate, LButtonDbClkDelegate, LButtonDownDelegate,
                LButtonUpDelegate, MouseMoveDelegate);
            SetID();
            Size = new Size(WIDTH, 60);

            GradientButtonColor gbc = new GradientButtonColor();

            gbc.NormalColor1 = Color.FromArgb(10, 10, 10);
            gbc.NormalColor2 = Color.FromArgb(40, 40, 40);
            gbc.NormalColor3 = Color.FromArgb(90, 90, 90);
            gbc.NormalColor4 = Color.FromArgb(150, 150, 150);

            gbc.PressedColor1 = Color.FromArgb(180, 180, 180);
            gbc.PressedColor2 = Color.FromArgb(180, 180, 180);
            gbc.PressedColor3 = Color.FromArgb(180, 180, 180);
            gbc.PressedColor4 = Color.FromArgb(180, 180, 180);

            GradientColor = gbc;
        }
        #endregion

        #region 函数
        /// <summary>
        /// 由系统绘制控件
        /// </summary>
        /// <param name="hdcDst"></param>
        /// <param name="prcWin"></param>
        /// <param name="prcUpdate"></param>
        protected override void OnDefaultPaintWin(IntPtr hdcDst, ref RECT prcWin, ref RECT prcUpdate)
        {
            UiButton_GradientWrapperDefaultPaintWin(Handle, hdcDst, ref prcWin, ref prcUpdate);
        }
        #endregion
    }
}
